package com.socialuni.sdk.utils;

import com.socialuni.sdk.model.DO.user.AccountDO;
import com.socialuni.sdk.repository.AccountRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class CommonUserAccountUtil {
    private static AccountRepository accountRepository;

    @Resource
    public void setCommonUserAccountRepository(AccountRepository accountRepository) {
        CommonUserAccountUtil.accountRepository = accountRepository;
    }

    public static AccountDO getMineAccountByProvider(String provider) {
        AccountDO accountDO = accountRepository.findByProviderAndUserId(provider, UserUtils.getMineUserId());
        return accountDO;
    }

    public static AccountDO getUserAccountByProvider(String provider, Integer userId) {
        AccountDO accountDO = accountRepository.findByProviderAndUserId(provider, userId);
        return accountDO;
    }
}
